<?php
include("../../config.php");
include(FILE_ROOT."/common/db.php");
include(FILE_ROOT."/common/Role.php");
include(FILE_ROOT."/common/user_client.php");
include(FILE_ROOT."/common/common_function.php");	
/*if(!checkIsLogin()){
    echo '{"status":-2,"message":"没有权限！","data":""}';
    return;
}*/

$role=new Role();
$op = empty($_POST["action"])?$_GET["action"]:$_POST["action"];
$db=new DB();
switch($op){ 
	case 'roleList':
		$data=$role->getRoleList();
		$role->data($data)->end();
		break;
	case 'authorization':
		$id = empty($_POST["id"])?$_GET["id"]:$_POST["id"];
		$r=$db->getOne("SELECT * from chu_role where id=".$id);
		$menus=$role->getAllMenu($r['id'],$r['name']);
		$role->data($menus)->end();
		break;
	case 'save':
		$id = empty($_POST["id"])?$_GET["id"]:$_POST["id"];
		$access = empty($_POST["access"])?$_GET["access"]:$_POST["access"];
		$role->save($id,$access);
		break;
	case 'addRole':
		$name=empty($_POST["name"])?$_GET["name"]:$_POST["name"];
		$status=empty($_POST["status"])?$_GET["status"]:$_POST["status"];
		$role->newRole($name,$status);
		break;
	case 'deleteRole':
		$id=empty($_POST["id"])?$_GET["id"]:$_POST["id"];
		$role->deleteRole($id);
		break;
	case 'userList':
		$token=$_COOKIE["CCUSER"];
		$role->getUserList($token);
		break;
	case 'userRole':
		//管理者token
		$token=$_COOKIE["CCUSER"];
		$uid=empty($_POST["uid"])?$_GET["uid"]:$_POST["uid"];
		$roleid=empty($_POST["roleid"])?$_GET["roleid"]:$_POST["roleid"];
		$role->getUserRole($uid,$roleid,$token);
		break;
	case 'changeRole':
		$uid=empty($_POST["uid"])?$_GET["uid"]:$_POST["uid"];
		$role_id=empty($_POST["role"])?$_GET["role"]:$_POST["role"];
		$role->changeRole($uid,$role_id);
		break;

}

?>